
#import "WWVarView.h"
#import "WWVarViewIBInspector.h"

@implementation WWVarViewIBInspector

- init 
{
   char buf[MAXPATHLEN + 1];
   id bundle = [NXBundle bundleForClass:[WWVarView class]];
    

   [super init];

   tclVarValueSize = 256;
   tclVarValue = (char *)NXZoneCalloc([self zone], tclVarValueSize, sizeof(char));

   [bundle getPath:buf forResource:[[self class] name] ofType:"nib"];
   [NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];

   // since the textView was "hidden" inside the ScrollView, we couldn't do this in IB, so...
   [tclVarValueText setDelegate:self];

   [self revert:self];

   return self;
}
//
- free
{
  //if (tclVarValue) { NXZoneFree([self zone], tclVarValue); }
  return [super free];
}
//
- revert:sender 
{
  [tclVarName setStringValue:[object tclVarName]];
  [tclVarType setStringValue:[object tclVarType]]; 
  [tclVarValueText setText:[object tclVarValue]];
  [restrictVarNameSwitch setIntValue:[object restrictDropToSameName]];
  [restrictVarTypeSwitch setIntValue:[object restrictDropToSameType]];
  [sourceSwitch setIntValue:[object actAsSource]];
  [sinkSwitch setIntValue:[object actAsSink]];
  return [super revert:sender];
}
//
- ok:sender
{
  int   cnt;


  cnt = [tclVarValueText textLength];
  while (cnt >= tclVarValueSize)
  {  tclVarValueSize *= 2;
     tclVarValue = (char *)NXZoneRealloc([self zone], tclVarValue, tclVarValueSize);
  }
  *tclVarValue = '\0';
  [tclVarValueText getSubstring:tclVarValue start:0 length:(cnt + 1)];
  [object setTclVarValue:tclVarValue];

  [object setTclVarName:[tclVarName stringValue]];
  [object setTclVarType:[tclVarType stringValue]];
  [object setRestrictDropToSameName:(BOOL)[restrictVarNameSwitch intValue]];
  [object setRestrictDropToSameType:(BOOL)[restrictVarTypeSwitch intValue]];
  [object setActAsSource:(BOOL)[sourceSwitch intValue]];
  [object setActAsSink:(BOOL)[sinkSwitch intValue]];

  return [super ok:sender]; 
}
//
- (BOOL)wantsButtons	{ return YES; }

// text delegate methods
- textDidChange:sender {  return [self touch:sender]; }



@end
